<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>"鸡兔同笼"问题</title>
    <script type="text/javascript">
        function myfunction(){
            let result=document.getElementById("result");
            console.log(result.innerText);
            let heads=parseInt(document.getElementById("head").value);
            let feet=parseInt(document.getElementById("foot").value);
            console.log(heads);
            console.log(feet);

            for(var ji=0;ji<=heads;ji++){
                var tu=heads-ji;
                if((ji*2)+(tu*4)===feet){
                    console.log("分别有鸡"+ji+"只，有兔子"+tu+"只");
                    result.innerText="分别有鸡"+ji+"只，有兔子"+tu+"只";
                    result.style.color="blue";
                    return;
                }
            }
            result.style.color="red";
            result.innerText="无解";

        }
    </script>
    <style>
        .container {
            width:60%;
            margin:0 auto;
            background-color: aqua;
            min-height: 220px;
        }

        h2 {
            text-align: center;
            padding-top: 10px;
        }

        p {
            width: 90%;
            margin: 0 auto;
            text-align: center;
        }

        input {
            box-sizing: border-box;
            width: 60px;
        }

        p#result {
            margin: 20px auto;
            height: 40px;
            width: 75%;
            padding: 20px;
            border: 1px dotted goldenrod;
            background-color: rgb(221,220,220);
            font-weight: bold;
        }
    </style>
</head>
<body>
    <div class="container">
        <h2>循环解决鸡兔同笼问题</h2>
        <p>鸡兔同笼，鸡兔一共
            <input type="number" value="" id="head">只，笼子里脚一共
            <input type="number" value="" id="foot">只，请问分别有多少只鸡和兔?
            <button onclick="myfunction()">计算</button>
        </p>
        <p id="result" typr="text"></p>
    </div>
</body>
</html>